#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>


void sys_err (const char *str){
	perror(str);
	exit(1);
}

void *tfn(void *arg)
{
	printf("thread: pid = %d, tid = %lu\n", getpid(), pthread_self());
	return NULL;
}

int main(int argc, char *argv[]){
	pthread_t tid;

	int ret = pthread_create(&tid, NULL, tfn, NULL);
	if (ret != 0){
		fprintf(stderr, "pthread_create error: %s\n", strerror(ret));
		exit(1);
	}
	ret = pthread_detach(tid);     // she zhi xian cheng fen li
	if (ret != 0){
		fprintf(stderr, "pthread_detach error: %s\n", strerror(ret));
		exit(1);
	}

	sleep(1);
	ret = pthread_join(tid, NULL);      // hui shou xian cheng
	if (ret != 0){
		fprintf(stderr, "pthread_join error: %s\n", strerror(ret));
		exit(1);
	}


	printf("main: pid = %d, tid = %lu\n", getpid(), pthread_self());

	pthread_exit((void *)0);
}
